#!/usr/bin/python
# -*- coding: UTF-8 -*-


print """
您可以使用点号 . 来访问对象的属性。使用如下类的名称访问类变量:

        emp1.displayEmployee()
        emp2.displayEmployee()
        print "Total Employee %d" % Employee.empCount

getattr(obj, name[, default]) : 访问对象的属性。
hasattr(obj,name) : 检查是否存在一个属性。
setattr(obj,name,value) : 设置一个属性。如果属性不存在，会创建一个新属性。
delattr(obj, name) : 删除属性。
"""

class Employee:
   '所有员工的基类'
   empCount = 0

   def __init__(self, name, salary):
      self.name = name
      self.salary = salary
      Employee.empCount += 1

   def displayCount(self):
       self.address="shagnahi";
       print "Total Employee %d" % Employee.empCount

   def displayEmployee(self):
       try:
           print self.address;
       except(Exception):
           print "没有 地址属性"
       finally:
           print "Name : ", self.name,  ", Salary: ", self.salary

       if hasattr(self,"address"):
            print "have the attr of address"
       else:
            print "have not the attr of address"





"创建 Employee 类的第一个对象"
emp1 = Employee("Zara", 2000)
"创建 Employee 类的第二个对象"
emp2 = Employee("Manni", 5000)
emp1.displayCount();
emp1.displayEmployee()
print "===================================="
emp2.displayEmployee()
print "Total Employee %d" % Employee.empCount